home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / image / codecs / bmp_dec.cc next >
Encoding:
C/C++ Source or Header  |  1997-02-02  |  1.9 KB  |  88 lines

  1. // bmp_dec.cc: Decoding an OS/2 bitmap file.
  2. // (c) Klaus Gebhardt, 1997
  3.  
  4. #include <octave/config.h>
  5.  
  6. #include <iostream.h>
  7.  
  8. #include <octave/lo-utils.h>
  9. #include <octave/lo-ieee.h>
  10. #include <octave/mx-base.h>
  11. #include <octave/str-vec.h>
  12.  
  13. #include <octave/defun-dld.h>
  14. #include <octave/error.h>
  15. #include <octave/gripes.h>
  16. #include <octave/help.h>
  17. #include <octave/mappers.h>
  18. #include <octave/oct-fstrm.h>
  19. #include <octave/oct-iostrm.h>
  20. #include <octave/oct-map.h>
  21. #include <octave/oct-obj.h>
  22. #include <octave/oct-prcstrm.h>
  23. #include <octave/oct-stream.h>
  24. #include <octave/oct-strstrm.h>
  25. #include <octave/ops.h>
  26. #include <octave/ov-base.h>
  27. #include <octave/ov-typeinfo.h>
  28. #include <octave/ov.h>
  29. #include <octave/ov-base.h>
  30. #include <octave/ov-re-mat.h>
  31. #include <octave/pager.h>
  32. #include <octave/pr-output.h>
  33. #include <octave/symtab.h>
  34. #include <octave/variables.h>
  35.  
  36. #include <octave/oct-img.h>
  37.  
  38. DEFUN_DLD (bmp_dec, args, ,
  39.   "bmp_dec (FILE)\n\
  40. \n\
  41. Decode the OS/2 or Windows bitmap in FILE.")
  42. {
  43.   octave_value_list retval;
  44.   retval (1) = -1.0;
  45.   retval (0) = -1.0;
  46.  
  47.   UCHAR **cmap;
  48.   INT **x;
  49.   INT col_min, col_max;
  50.   UINT i, j, nr, nc;
  51.  
  52.   int nargin = args.length ();
  53.  
  54.   if (nargin == 1)
  55.     {
  56.       if (!args(0).is_string ())
  57.     {
  58.       ::error ("bmp_dec: first argument must be a string");
  59.       return retval;
  60.     }
  61.  
  62.       string filename = args(0).string_value ();
  63.  
  64.       FILE *fp = fopen (filename.c_str (), "rb");
  65.  
  66.       if (fp)
  67.     {
  68.       if (BMP_Decode (fp, &nc, &nr, &col_min, &col_max, &cmap, &x) != 0)
  69.         {
  70.           fclose (fp);
  71.           ::error ("bmp_dec: error reading bitmap");
  72.           return retval;
  73.         }
  74.  
  75.       retval(1) = oct_colormap(cmap, col_min, col_max);
  76.       retval(0) = oct_pixels (x, col_min, nr, nc);
  77.  
  78.       fclose (fp);
  79.     }
  80.       else
  81.     ::error ("bmp_dec: unable to open \"%s\"", filename.c_str ());
  82.     }
  83.   else
  84.     print_usage ("bmp_dec");
  85.  
  86.   return retval;
  87. }
  88.